﻿Imports System.Data.SqlClient

Public Class PreparedStatement
    Public Property strSql As String
    Public Property parameters As New Hashtable

    Public Sub New(ByVal sql As String)
        Me.strSql = sql
    End Sub

    Public Sub addParameter(ByVal key As String, ByVal value As Object)
        If parameters.ContainsKey(key) Then
            parameters.Remove(key)
        End If
        parameters.Add(key, value)
    End Sub

    Public Function getSqlCommand(ByRef conn As System.Data.SqlClient.SqlConnection) As SqlCommand
        Dim cmd As New SqlCommand(Me.strSql, conn)
        For Each k As String In Me.parameters.Keys
            cmd.Parameters.Add(New SqlParameter("@" & k, Me.parameters.Item(k)))
        Next
        Return cmd
    End Function
End Class
